/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

using System;
using Orm;
using System.Collections;
using NHibernate;

namespace petshop {
	/// <summary>
	/// ORM-Persistable Class
	/// </summary>
	public class TransactionFactory {
		public static global::petshop.Transaction LoadTransactionByORMID(int ID) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return LoadTransactionByORMID(session,ID);
		}
		
		public static global::petshop.Transaction LoadTransactionByORMID(PersistentSession session,int ID) {
			return (global::petshop.Transaction) session.Load(typeof(global::petshop.Transaction), (Int32)ID);
		}
		
		public static global::petshop.Transaction[] ListTransactionByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return ListTransactionByQuery(session, condition, orderBy);
		}
		
		public static global::petshop.Transaction[] ListTransactionByQuery(PersistentSession session, string condition, string orderBy) {
			global::System.Text.StringBuilder sb = new global::System.Text.StringBuilder("From petshop.Transaction as Transaction");
			if (condition != null) {
				sb.Append(" Where ");
				sb.Append(condition);
			}
			if (orderBy != null) {
				sb.Append(" Order By ");
				sb.Append(orderBy);
			}
			IQuery query = session.CreateQuery(sb.ToString());
			try {
				IList list = query.List();
				global::petshop.Transaction[] result = new global::petshop.Transaction[list.Count];
				list.CopyTo(result, 0);
				return result;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public static global::petshop.Transaction LoadTransactionByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return LoadTransactionByQuery(session, condition, orderBy);
		}
		
		public static global::petshop.Transaction LoadTransactionByQuery(PersistentSession session, string condition, string orderBy) {
			global::petshop.Transaction[] transactions = ListTransactionByQuery(session, condition, orderBy);
			if (transactions != null && transactions.Length > 0)
				return transactions[0];
			else
				return null;
		}
		
		public static global::System.Collections.IEnumerable IterateTransactionByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return IterateTransactionByQuery(session, condition, orderBy);
		}
		
		public static global::System.Collections.IEnumerable IterateTransactionByQuery(PersistentSession session, string condition, string orderBy) {
			global::System.Text.StringBuilder sb = new global::System.Text.StringBuilder("From petshop.Transaction as Transaction");
			if (condition != null) {
				sb.Append(" Where ");
				sb.Append(condition);
			}
			if (orderBy != null) {
				sb.Append(" Order By ");
				sb.Append(orderBy);
			}
			IQuery query = session.CreateQuery(sb.ToString());
			try {
				return query.Enumerable();
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public static Transaction CreateTransaction() {
			return new global::petshop.Transaction();
		}
		
		public Transaction LoadTransactionByCriteria(TransactionCriteria transactionCriteria) {
			Transaction[] transactions = ListTransactionByCriteria(transactionCriteria);
			if(transactions == null || transactions.Length == 0) {
				return null;
			}
			return transactions[0];
		}
		
		public Transaction[] ListTransactionByCriteria(TransactionCriteria transactionCriteria) {
			return transactionCriteria.ListTransaction();
		}
	}
	
}
